package extractLatAndLon;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class dateFromYago {

	public static void main(String[] args) {
		String inFilePath = "F:/yago/yagoMetaFacts.ttl";
		String datePath = "dateFromYago.txt";
		File inFile = new File(inFilePath);
		File dateOutputFile = new File(datePath);
		try {
			FileReader inReader = new FileReader(inFile.getAbsolutePath());
			FileWriter dateWriter = new FileWriter(dateOutputFile.getAbsolutePath(), true);
			BufferedReader bReader = new BufferedReader(inReader);
			BufferedWriter bDateWriter = new BufferedWriter(dateWriter);
			String aLine = "", date = "";
			while ((aLine = bReader.readLine()) != null) {
				Pattern pattern = Pattern.compile("[0-9]{4}-[0-9]{2}-[0-9]{2}");
				Matcher matcher = pattern.matcher(aLine);
				if (matcher.find()) {
					date = matcher.group(0);
					bDateWriter.write(date + "\n");
					bDateWriter.flush();
				}
			}
			inReader.close();
			bReader.close();
			bDateWriter.close();
			dateWriter.close();

		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
